package org.obp.ons.client;

import com.aliyun.openservices.ons.api.bean.ProducerBean;
import org.obp.ons.config.OnsConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqProducerClient {

    @Autowired
    private OnsConfig onsConfig;

    @Bean(initMethod = "start", destroyMethod = "shutdown")
    @ConditionalOnProperty(name = "ons.rocketmq.enable", havingValue = "true")
    public ProducerBean buildProducer() {
        ProducerBean producer = new ProducerBean();
        producer.setProperties(onsConfig.getMqProperties());
        return producer;
    }

}
